package com.situ.blog.util;

public class Result {
    public static final int ERROR = 1;
    public static final int OK = 0;
    public static final int NO_PERMISSION = 2;
    private Integer code;
    private String msg;
    private Object data;

    public boolean isOK () {
        return code == OK;
    }

    public Result() {
    }

    public Result(Integer code) {
        this.code = code;
    }

    public Result(Integer code, String msg) {
        this.code = code;
        this.msg = msg;
    }

    public Result(Integer code, Object data) {
        this.code = code;
        this.data = data;
    }

    public Result(Integer code, String msg, Object data) {
        this.code = code;
        this.msg = msg;
        this.data = data;
    }

    public static Result ok() {
        return new Result(OK);
    }

    public static Result ok(String msg) {
        return new Result(OK, msg);
    }

    public static Result ok(Object data) {
        return new Result(OK, data);
    }

    public static Result ok(String msg, Object data) {
        return new Result(OK, msg, data);
    }

    public static Result error() {
        return new Result(ERROR);
    }

    public static Result error(String msg) {
        return new Result(ERROR, msg);
    }

    public Integer getCode() {
        return code;
    }

    public void setCode(Integer code) {
        this.code = code;
    }

    public String getMsg() {
        return msg;
    }

    public void setMsg(String msg) {
        this.msg = msg;
    }

    public Object getData() {
        return data;
    }

    public void setData(Object data) {
        this.data = data;
    }
}
